package com.qzsoft.zhjd.machine.modules.machinefuel.controller;

import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.jeemis.common.validator.ValidatorUtils;
import com.qzsoft.zhjd.common.enums.BizCode;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.machine.modules.machinefuel.dto.MachineRefuelRecordsDto;
import com.qzsoft.zhjd.machine.modules.machinefuel.entity.MachineRefuelRecordsEntity;
import com.qzsoft.zhjd.machine.modules.machinefuel.service.MachineRefuelRecordsService;

/**
 * @ClassName MachineRefuelRecordsController
 * @Description 设备加油记录控制器
 * @author linhuawei
 * @since 2021-11-04
 */
@RestController
@RequestMapping("/api/machineRefuelRecords")
public class MachineRefuelRecordsController {

    @Autowired
    private MachineRefuelRecordsService machineRefuelRecordsService;

    /**
     * @Title page
     * @Description
     * @param params
     * @return
     */
    @RequiresPermissions("api:machinerefuelrecords:list")
    @GetMapping("/page")
    public Result<IPage<MachineRefuelRecordsDto>> page(@RequestParam Map<String, Object> params) {
        IPage<MachineRefuelRecordsDto> page = machineRefuelRecordsService.pageDto(params);
        return ResultUtils.ok(page);
    }

    /**
     * @Title pageForMachine
     * @Description 指定设备加油记录
     * @param machineId 设备主键
     * @param params 查询条件
     * @return 指定设备加油记录
     */
    @GetMapping("/page/{machineId}")
    public Result<IPage<MachineRefuelRecordsEntity>> pageForMachine(@PathVariable("machineId") String machineId, @RequestParam Map<String, Object> params) {
        IPage<MachineRefuelRecordsEntity> page = machineRefuelRecordsService.pageForMachine(machineId, params);
        return ResultUtils.ok(page);
    }

    /**
     * @Title find
     * @Description 查询加油记录
     * @param id 加油记录主键
     * @return 查询结果
     */
    @RequiresPermissions("api:machinerefuelrecords:edit")
    @GetMapping("/find/{id}")
    public Result<MachineRefuelRecordsEntity> find(@PathVariable("id") String id) {
        MachineRefuelRecordsEntity entity = machineRefuelRecordsService.getById(id);
        if (null == entity) {
            return ResultUtils.error(BizCode.DATA_NOT_FOUND);
        }
        return ResultUtils.ok(entity);
    }

    /**
     * @Title update
     * @Description 修改加油记录数据
     * @param entity 加油记录数据
     * @return 修改结果
     */
    @PostMapping("/update")
    public Result<String> update(@RequestBody MachineRefuelRecordsEntity entity) {
        ValidatorUtils.validateEntity(entity);
        machineRefuelRecordsService.updateById(entity);
        return ResultUtils.ok();
    }

}
